package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/8/29 09:06
 * @apiNote
 */

public class Test03142SatisfiesConditions {
    public boolean satisfiesConditions(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        for (int i = 0; i < n; i++) {
            for (int j = m - 2; j >= 0; j--) {
                if (grid[j][i] != grid[j + 1][i]) {
                    return false;
                }
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n - 1; j++) {
                if (grid[i][j] == grid[i][j + 1]) {
                    return false;
                }
            }
        }
        return true;
    }

    public boolean satisfiesConditions1(int[][] grid) {
        int m = grid.length;
        int n = grid[0].length;
        for(int i =0;i<m;i++){
            for(int j = 0;j<n;j++){
                if(i != m-1 && grid[i][j] != grid[i+1][j]){
                    return false;
                }
                if(j != n-1 && grid[i][j] == grid[i][j+1]){
                    return false;
                }
            }
        }
        return true;
    }
}
